/********************************************
 * 功能说明: 
 * 模块名称: 
 * 系统名称: 
 * 软件版权: 北京银杉金服科技有限公司
 * 系统版本: 1.0.0
 * 开发人员: zhangfb
 * 开发时间: 2018/9/23 22:18
 * 审核人员: 
 * 相关文档: 
 * 修改记录: 修改日期 修改人员 修改说明
 *********************************************/
package com.hyacinth.config;

import com.hyacinth.web.filter.CORSFilter;
import com.hyacinth.web.interceptor.TokenInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 全局mvc配置
 * @author zhangfb
 * @version 1.0.0.1
 * @since JDK 1.8
 */
@Order(value = 10)
@Configuration
public class GlobalWebMvcConfigurer implements WebMvcConfigurer{

    private final TokenInterceptor tokenInterceptor;
    private final CORSFilter corsFilter;

    @Autowired
    public GlobalWebMvcConfigurer(TokenInterceptor tokenInterceptor, CORSFilter corsFilter) {
        this.tokenInterceptor = tokenInterceptor;
        this.corsFilter = corsFilter;
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 添加一个拦截器，连接以/yunpi为前缀的 url路径
        registry.addInterceptor(tokenInterceptor).addPathPatterns("/base/**","/daq/**","/dcl/**","/dsf/**");
    }

    /**
     * 用来配置urlpattern 来确定哪些路径触发filter
     */
    @Bean
    public FilterRegistrationBean someFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean(corsFilter);
        registration.addUrlPatterns("/*");
        registration.setOrder(5); //设置执行顺序
        return registration;
    }
}
